package com.zego.wawaji.ui.dialog.share;

import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zego.wawaji.R;
import com.zego.wawaji.base.module.ModuleMgr;
import com.zego.wawaji.ui.base.BaseDialogFragment;

/**
 * 分享弹出框
 */
public class ShareDialog extends BaseDialogFragment implements View.OnClickListener {
    private TextView tv_title;
    private OnShareClickListener shareListener;
    double heightRatio = 0;

    public ShareDialog() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        setContentView(R.layout.share_dialog);
        heightRatio = getContentView().getHeight() / ModuleMgr.getAppMgr().getScreenHeight();
        setDialogSizeRatio(1, heightRatio);
        setCanceledOnTouchOutside(true);
        settWindowAnimations(R.style.AnimDownInDownOut);
        setGravity(Gravity.BOTTOM);
        if (onCreateView != null) {
            onCreateView.onCreateViewOk();
        }
        initView();
        return getContentView();
    }

    private void initView() {
        tv_title = (TextView) findViewById(R.id.tv_title);
        findViewById(R.id.share_weixin).setOnClickListener(this);
        findViewById(R.id.share_wx_circle).setOnClickListener(this);
        findViewById(R.id.share_link).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (shareListener == null) return;

        switch (v.getId()) {
            case R.id.share_weixin:
                shareListener.shareWeiXin();
                break;

            case R.id.share_wx_circle:
                shareListener.shareWXCircle();
                break;

            case R.id.share_link:
                shareListener.shareLink();
                break;

            default:
                break;
        }
    }

    /**
     * 创建UI后的回调事件
     */
    private OnCreateView onCreateView = null;

    public interface OnCreateView {
        void onCreateViewOk();
    }

    /**
     * 初始化完成调用
     *
     * @param onCreateView
     */
    public void setOnCreateView(OnCreateView onCreateView) {
        this.onCreateView = onCreateView;
    }

    /**
     * 设置tip标题
     *
     * @param txt
     */
    public ShareDialog setTitle(String txt) {
        tv_title.setText(txt);
        return this;
    }

    /**
     * 设置分享按钮回调
     */
    public ShareDialog setOnShareListener(OnShareClickListener listener) {
        shareListener = listener;
        return this;
    }

    public interface OnShareClickListener {
        void shareWeiXin();

        void shareWXCircle();

        void shareLink();
    }
}
